﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;

namespace CorporationWars
{
    [Serializable]
    public class UIButton : UIZone
    {
        public Color HoverColor { get; set; }
        public Color MouseDownColor { get; set; }

        public bool HasShadowOnUp { get; set; }
        public int ShadowHeight { get; set; }
        protected Rectangle ShadowRect
        {
            get
            {
                if(!IsMouseOver)
                    return new Rectangle((int)Position.X - ShadowHeight, (int)Position.Y + ShadowHeight, Width, Height);
                else
                    return new Rectangle((int)Position.X - ShadowHeight / 2, (int)Position.Y + ShadowHeight/2, Width, Height);
            }
        }

        public Color shadwoColor = new Color(0, 0, 0, .5f);

        public UIButton(Game1 game) : base(game) { HasShadowOnUp = false; ShadowHeight = 8; }

        
        public override void Draw(GameTime gameTime)
        {
            if (!IsVisible)
                return;

            if (!IsMouseOver)
            {
                if (HasShadowOnUp)
                    spriteBatch.Draw(Game.Content.Load<Texture2D>(TextureAsset), ShadowRect, shadwoColor);

                spriteBatch.Draw(Game.Content.Load<Texture2D>(TextureAsset), renderRectangle, Color);
            }
            else
            {
                if (!IsMouseDown)
                {
                    if (HasShadowOnUp)
                        spriteBatch.Draw(Game.Content.Load<Texture2D>(TextureAsset), ShadowRect, shadwoColor);

                    spriteBatch.Draw(Game.Content.Load<Texture2D>(TextureAsset), renderRectangle, HoverColor);
                    DrawToolTip(gameTime);
                }
                else
                    spriteBatch.Draw(Game.Content.Load<Texture2D>(TextureAsset), renderRectangle, MouseDownColor);
            }
        }

    }
}
